﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Caliburn.Micro.BikeWizard.Utils
{
    /// <summary>
    /// Alows any action to implement IResult, so it can be executed using Co-Routines
    /// </summary>
    public class ActionResult : IResult
    {
        #region Private Members
        private System.Action<ActionResult> actionToPerform;
        #endregion

        #region Public Methods
        public void SetComplete(object sender)
        {
            Completed(this, new ResultCompletionEventArgs() { Error = null, WasCancelled = false });
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Set up an IResult action. The action will be executed when the Execute() method is called.
        /// </summary>
        /// <param name="actionToPerform">The action to perform. The caller has to make sure that it fires the IResult.Completed event</param>
        public ActionResult(System.Action<ActionResult> actionToPerform)
        {
            this.actionToPerform = actionToPerform;
        }
        #endregion

        #region IResult Implementation
        /// <summary>
        /// Execute the actionToPerform action that was passed when creating the ActionIResult instance
        /// </summary>
        /// <param name="context"></param>
        public void Execute(ActionExecutionContext context)
        {
            actionToPerform(this);
        }

        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };
        #endregion
    }
}
